<?php
namespace app\home\controller;
use think\Controller;
class digg extends Controller{  
    public function index(){
		$param = zanpiancms_param_url();
		$name=htmlspecialchars(input('name/s',''));
		$model=$GLOBALS['config']['model'][$param['sid']];
		if($param['id'] && $param['type'] && $model['name']){
			$data=$this->show($param['id'],$param['type'],$model['name'],$name);
		}else{
			$data=['msg'=>'参数错误','code'=>'-1'];
		}
		return json($data);
    }
	public function show($id='',$type='',$model,$name){
		$name=!empty($name)?$name:'点评';
		$cookiename=md5('digg-'.ip2long(request()->ip()).'-'.intval($id).'-'.intval($model));
		$cookie = cookie($cookiename);	
		if($cookie){
			return array('msg'=>$name.'速度太快休息一会吧！','code'=>'-1'); 
		}	
		if(in_array($type,array('up','down'))){
			db($model)->where($model.'_id',$id)->setInc($model.'_'.$type);
			cookie($cookiename,true,intval($GLOBALS['config']['user']['sys']['user_digg_time']));
			return array('msg'=>$name.'成功','code'=>1); 
		}
		return array('msg'=>'参数错误','code'=>'-1'); 		
	}			
}
// +----------------------------------------------------------------------
// | ZanPianCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.zanpian.com All rights reserved.
// +----------------------------------------------------------------------
// | BBS:  <http://www.feifeicms.cc>
// +----------------------------------------------------------------------
